package org.dromara.xyyw.service.impl;

import org.dromara.common.core.utils.MapstructUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.dromara.xyyw.domain.XyywCouponUsageRecord;
import org.dromara.xyyw.domain.bo.XyywCouponUsageRecordBo;
import org.dromara.xyyw.domain.query.XyywCouponUsageRecordQuery;
import org.dromara.xyyw.domain.vo.XyywCouponUsageRecordVo;
import org.dromara.xyyw.mapper.XyywCouponUsageRecordMapper;
import org.dromara.xyyw.service.IXyywCouponUsageRecordService;

import java.util.Collection;
import java.util.List;

/**
 * 优惠券使用记录Service业务层处理
 *
 * @author yf
 * @date 2024-05-29
 */
@Service
public class XyywCouponUsageRecordServiceImpl extends ServiceImpl<XyywCouponUsageRecordMapper, XyywCouponUsageRecord> implements IXyywCouponUsageRecordService {

    /**
     * 查询优惠券使用记录
     *
     * @param usageId 主键
     * @return XyywCouponUsageRecordVo
     */
    @Override
    public XyywCouponUsageRecordVo queryById(Integer usageId) {
        return baseMapper.selectVoById(usageId);
    }

    /**
     * 查询优惠券使用记录列表
     *
     * @param query 查询对象
     * @return XyywCouponUsageRecordVo
     */
    @Override
    public TableDataInfo<XyywCouponUsageRecordVo> queryPageList(XyywCouponUsageRecordQuery query) {
        return PageQuery.of(() -> baseMapper.queryList(query));
    }

    /**
     * 查询优惠券使用记录列表
     *
     * @param query 查询对象
     * @return XyywCouponUsageRecordVo
     */
    @Override
    public List<XyywCouponUsageRecordVo> queryList(XyywCouponUsageRecordQuery query) {
        return baseMapper.queryList(query);
    }

    /**
     * 根据新增业务对象插入优惠券使用记录
     *
     * @param bo 优惠券使用记录新增业务对象
     * @return Boolean
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean insertByBo(XyywCouponUsageRecordBo bo) {
        XyywCouponUsageRecord add = MapstructUtils.convert(bo, XyywCouponUsageRecord.class);
        return save(add);
    }

    /**
     * 根据编辑业务对象修改优惠券使用记录
     *
     * @param bo 优惠券使用记录编辑业务对象
     * @return Boolean
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean updateByBo(XyywCouponUsageRecordBo bo) {
        XyywCouponUsageRecord update = MapstructUtils.convert(bo, XyywCouponUsageRecord.class);
        return updateById(update);
    }

    /**
     * 校验并批量删除优惠券使用记录信息
     *
     * @param ids 主键集合
     * @return Boolean
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean deleteWithValidByIds(Collection<Integer> ids) {
        return removeByIds(ids);
    }
}
